package com.dmpp.mes.service.impl;

import com.dmpp.mes.bean.RespEnum;
import com.dmpp.mes.bean.ResponseData;
import com.dmpp.mes.dao.ProductAndProcessMapper;
import com.dmpp.mes.parameterInfo.ProductAndProcess;
import com.dmpp.mes.service.ProductAndProcessService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service(value = "ProductAndProcessService")
public class ProductAndProcessServiceImpl implements ProductAndProcessService {
    @Autowired
    ProductAndProcessMapper mapper;

    @Override
    public ResponseData findAll( ) {
        ResponseData responseData = new ResponseData();
        List<ProductAndProcess> productAndProcesses=mapper.findAll();
        PageInfo pageInfo = new PageInfo<>(mapper.findAll());
        responseData.setData(pageInfo);
        return responseData;
    }

    @Override
    public ResponseData findByProductNo(String productNo) {
        ResponseData responseData = new ResponseData();
        responseData.setData(mapper.findByProductNo(productNo));
        return responseData;
    }

    @Override
    public ResponseData insert(ProductAndProcess productAndProcess) {
        ResponseData responseData = new ResponseData();
        ProductAndProcess productAndProcess1= mapper.findByProductNo(productAndProcess.getProductNo());
        if (productAndProcess1==null){
            mapper.insert(productAndProcess);
        }else {
            responseData.setCodeEnum(RespEnum.ERROR2001);
        }
        return responseData;
    }

    @Override
    public ResponseData updateByProductNo(ProductAndProcess ProductAndProcess) {
        ResponseData responseData = new ResponseData();
        mapper.updateByProductNo(ProductAndProcess);
        return responseData;
    }

    @Override
    public ResponseData deleteByProductNo(String productNo) {
        ResponseData responseData = new ResponseData();
        mapper.deleteByProductNo(productNo);
        responseData.setCodeEnum(RespEnum.SUCCESS);
        return responseData;
    }
}
